package edu.scau.mis.web.config;

import com.alipay.api.DefaultAlipayClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 沙箱支付配置
 */
@Data
@ConfigurationProperties("myalipay")	// 第三步中yml配置的前缀
@Configuration
public class AlipayConfig {
    /**
     * 沙箱支付网关
     */
    private String gateway;
    /**
     * 应用Id
     */
    private String appId;
    /**
     * 应用私钥
     */
    private String appPrivateKey;
    /**
     * 支付宝公钥
     */
    private String alipayPublicKey;

    /**
     * 参数返回格式
     */
    public static final String FORMAT = "JSON";
    /**
     * 编码方式
     */
    public static final String CHARSET = "UTF-8";
    /**
     * 签名方式
     */
    public static final String SIGN_TYPE = "RSA2";

    @Bean
    public DefaultAlipayClient defaultAlipayClient() {
        return new DefaultAlipayClient(
                gateway,
                appId,
                appPrivateKey,
                FORMAT,
                CHARSET,
                alipayPublicKey,
                SIGN_TYPE
        );
    }
}
